package com.nfc.base.Entity;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;

@Entity
@Table(name="users")
public class User {

	private int user_id;
	
	private Staff staff_id;
	
	private String password;
	
	private Staff created_by;
	
	private Date created_on;
	
	private Staff changed_by;
	
	private Date changed_on;
	


	@Id
	@Column(name="user_id", unique = true, nullable = false)
	@SequenceGenerator(name="users_id_seq", sequenceName="users_user_id_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="users_id_seq")
	

	public int getUser_id() {
		return user_id;
	}

	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}
	
	
	
	

	
	@OneToOne
	@JoinColumn(name="staff_id")
	public Staff getStaff_id() {
		return staff_id;
	}

	public void setStaff_id(Staff staff_id) {
		this.staff_id = staff_id;
	}

	@Column(name="password")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="created_by", referencedColumnName = "staff_id")
	public Staff getCreated_by() {
		return created_by;
	}

	public void setCreated_by(Staff created_by) {
		this.created_by = created_by;
	}


	@Column(name="created_on")	
	@Type(type="date")
	@Temporal(TemporalType.DATE)
	public Date getCreated_on() {
		return created_on;
	}

	public void setCreated_on(Date created_on) {
		this.created_on = created_on;
	}


	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="changed_by", referencedColumnName = "staff_id")
	public Staff getChanged_by() {
		return changed_by;
	}

	public void setChanged_by(Staff changed_by) {
		this.changed_by = changed_by;
	}


	@Column(name="changed_on")	
	@Type(type="date")
	@Temporal(TemporalType.DATE)
	public Date getChanged_on() {
		return changed_on;
	}

	public void setChanged_on(Date changed_on) {
		this.changed_on = changed_on;
	}

	@Override
	public String toString() {
		return "User [user_id=" + user_id + ", staff_id=" + staff_id
				+ ", password=" + password + ", created_by=" + created_by
				+ ", created_on=" + created_on + ", changed_by=" + changed_by
				+ ", changed_on=" + changed_on + "]";
	}



	
	
	
	
	
}
